#include <cstdio>

int main() {
	int a, b, d;
	scanf("%d%d%d", &a, &b, &d);
	int sum = a + b;
	int ans[31], num = 0;

	while (sum != 0) {
		ans[num++] = sum % d;
		sum /= d;
	}

	for (int i = num-1; i >= 0; i--) {
		printf("%d\n", ans[i]);
	}

	return 0;
}
